package com.aichongbang.acb.controller;



import com.aichongbang.acb.po.Item;
import com.aichongbang.acb.service.IItemService;
import com.aichongbang.acb.util.ResultVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author acb
 * @since 2021-05-27
 */
@RestController
@RequestMapping("/item")
public class ItemController {

    @Resource
    private IItemService itemService;

    @PostMapping("getAllItems")
    public ResultVO getAllItems(){
        List<Item> list = itemService.getAllItems();
        return ResultVO.success(list);

    }


    @GetMapping("deleteItem")
    public boolean deleteItem(HttpServletRequest request) {
        String tid = request.getParameter("tid");
        Integer id = Integer.parseInt(tid);
        boolean b = itemService.deletedItem(id);
        return b;
    }


    @GetMapping("getItemById")
    public Item getItemById(HttpServletRequest request) {
        String tid = request.getParameter("tid");
        Integer id = Integer.parseInt(tid);
        Item item = itemService.getItemById(id);
        return item;
    }




}
